require('./jquery.ztree.core.min.js');
require('./jquery.ztree.exedit.min.js');
require('./jquery.ztree.excheck.min.js');
function zTree() {
    return {
        restrict: 'E',
        scope: {
            zOption: '=',
            zConfig: '='
        },
        css: require('./metroStyle/metroStyle.css'),
        link: link
    }

    function link(scope, el) {
        scope.$watch(function() {
            return scope.zOption;
        }, function(value) {
            if (value)
                refreshTree();
        }, true);

        function refreshTree() {
            $.fn.zTree.init($(el), scope.zConfig, scope.zOption);
            scope.ztree = $.fn.zTree.getZTreeObj($(el).attr('id'));
        }
    }
}

module.exports = zTree;
